<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/11 0011
 * Time: 16:42
 */

namespace app\api\controller\v1\cleaner;


use app\api\controller\v1\Cleaner;
use app\currency\service\CleanerService;

class TimePlan extends Cleaner
{
    /**
     * 查询当前工作时间
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $this->success('查询工作时间成功！',CleanerService::getTimePlan($this->cid));
    }

    /**
     * 修改工作时间
     */
    public function save()
    {
        $data = $this->_input([
            'time_slot' => $this->request->post('time_slot',[])
        ],[
            'time_slot' => 'array'
        ],[
            'time_slot.array' => '数据格式错误！'
        ]);
        $res = CleanerService::setTimePlan($this->cid,$data['time_slot']);
        if(!is_array($res) || !isset($res['code']) || !isset($res['msg']))
        {
            $this->error('设置工作时间失败！');
        }
        if($res['code'] === 1){
            $this->success('设置工作时间成功！');
        } else {
            $this->error('设置工作时间失败：'.$res['msg']);
        }
    }
}